package cn.btks.resultintegration.rule.controller;

import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import cn.btks.resultintegration.achievements.pojo.LayerFeatures;
import cn.btks.resultintegration.achievements.pojo.TextAchievements;
import cn.btks.resultintegration.achievements.service.LayerFeaturesService;
import cn.btks.resultintegration.achievements.service.TextAchievementsService;
import cn.btks.resultintegration.rule.pojo.ProjectCategory;
import cn.btks.resultintegration.rule.pojo.VectorRules;
import cn.btks.resultintegration.rule.service.VectorRulesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lijun
 * @Date 2021/2/23 11:17
 */
@RestController
@RequestMapping("api/v1.0/resultIntegration/rule")
@Api(tags = "规则模块")
@Validated
public class VectorRulesController {

    @Autowired
    VectorRulesService vectorRulesService;

    @Autowired
    LayerFeaturesService layerFeaturesService;

    @Autowired
    TextAchievementsService textAchievementsService;

    @GetMapping("/vectorRules/findAllByContent/{content}")
    @ApiOperation("根据主要内容查询重点图层空间规则")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "content", value = "主要内容名称", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAllByContent(@PathVariable("content") String content) {
        List<VectorRules> vectorRulesList = vectorRulesService.findAllByContent(content);
        return vectorRulesList != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), vectorRulesList) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/layerFeatures/findByName/{name}")
    @ApiOperation("根据文件英文名查询要素管控要求")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "name", value = "文件英文名称", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findByName(@PathVariable("name") String name) {
        LayerFeatures layerFeatures = layerFeaturesService.findByName(name);
        return layerFeatures != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), layerFeatures) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/dataPresentation/text/findByUnitCode/{unitCode}")
    @ApiOperation("根据管控单元编码查询成果数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "unitCode", value = "管控单元编码", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findById(@PathVariable("unitCode") String unitCode) {
        TextAchievements textAchievements = textAchievementsService.findByUnitCode(unitCode);
        return textAchievements != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), textAchievements) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }
}
